//
//  UITextField+Style.m
//  XYZKitDemo
//
//  Created by 谢英泽 on 2016/11/20.
//  Copyright © 2016年 谢英泽. All rights reserved.
//

#import "UITextField+Style.h"

@implementation UITextField (Style)

#pragma mark - 设置textField的属性

- (void)setTextFieldPlaceHolder:(NSString *)placeHolder textFont:(UIFont *)textFont textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment {
    self.placeholder = placeHolder;
    self.font = textFont;
    self.textColor = textColor;
    self.textAlignment = textAlignment;
}

#pragma mark - 设置PlaceholderColor
/**
 设置placeholder颜色
 */
- (void)setPlaceholderColor:(UIColor *)color {
    [self setValue:color forKeyPath:@"_placeholderLabel.textColor"];
}

/**
 限制最大金额输入
 */
- (void)limitMoneyInputCompare:(CGFloat)maxNumber {
    if ([self.text containsString:@"."]) {
        NSArray *array = [self.text componentsSeparatedByString:@"."];
        NSString *lastString = array[1];
        if (lastString.length > 2) {
            self.text = [self.text substringToIndex:self.text.length - 1];
        }
    }
    if ([self.text floatValue] > maxNumber) {
        self.text = [self.text substringToIndex:self.text.length - 1];
        return ;
    }
}

@end
